package com.homework.feign;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.api.R;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.homework.entity.Comment;
import com.homework.search.dto.PostDTO;
import com.homework.service.PostService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/hw-blog")
public class HwBlogFiegn {

    @Autowired
    PostService postService;

    @GetMapping("/findPostDTOByPostId")
    public R<PostDTO> findPostDTOByPostId(long postId) {

        PostDTO postDTO = postService.findPostDTOById(postId);

        return R.ok(postDTO);
    }

    @PostMapping("/findPostDTOByPage")
    R<List<PostDTO>> findPostDTOByPage(@RequestParam("current") int current, @RequestParam("size") int size){

        Page<PostDTO> page = new Page<>();
        page.setCurrent(current);
        page.setSize(size);

        IPage<PostDTO> pageData = postService.findPostDTOByPage(page, null);

        return R.ok(pageData.getRecords());
    }
}
